<template>
  <div id="exportReport">
    <el-button type="primary" icon="el-icon-download" @click="exportToExcel(headName, filterVal, data, fileName)">下载报表
    </el-button>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        value: ['', '']
      }
    },
    props: {
      headName: Array,
      filterVal: Array,
      data: Array,
      fileName: String
    },



    methods: {
      exportToExcel(tHeader, filterVal, list, fileName) {
        // excel数据导出
        require.ensure([], () => {
          const { export_json_to_excel } = require('@/utils/vendor/Export2Excel.js')
          const data = this.formatJson(filterVal, list)
          export_json_to_excel(tHeader, data, fileName)
        })
      },
      formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
      },
    }
  }
</script>
<style scoped>
  .saas-icon-icon-close {
    font-size: 16px;
    position: relative;
    top: 2px;
  }
</style>